#include <iostream>
#include <map>
#include <string>

using namespace std;

/**
 * 小黑的藏书
 */
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    map<string, int> books;

    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string book;
        cin >> book;
        if (books.count(book)){
            books[book] += 1;
        }else{
            books[book] = 1;
        }
    }

    cout << books.size() << "\n";

    for(auto it = books.begin(); it != books.end(); it++){
        cout << it->first << " " << it->second << "\n";
    }

    return 0;
}